package lumingweihua.future.cn.lumingweihua.ui.mine;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zhusx.core.interfaces.IHttpResult;
import com.zhusx.core.network.HttpRequest;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import lumingweihua.future.cn.lumingweihua.R;
import lumingweihua.future.cn.lumingweihua.network.LoadData;
import lumingweihua.future.cn.lumingweihua.network.LoadingHelper;
import lumingweihua.future.cn.lumingweihua.ui.BaseCompatActivity;
import lumingweihua.future.cn.lumingweihua.ui.mine.domain.ReviewData;

/**
 * todo 货主认证审核进度
 * Author       zhusx
 * Email        327270607@qq.com
 * Created      2018/3/15 16:57
 */

public class ReviewProgressActivity extends BaseCompatActivity {
    @BindView(R.id.iv_image)
    ImageView ivImage;
    @BindView(R.id.tv_message)
    TextView tvMessage;
    @BindView(R.id.layout_content)
    RelativeLayout layoutContent;
    @BindView(R.id.tv_submit)
    TextView tvSubmit;

    final int REQUEST_ID = 22;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);
        ButterKnife.bind(this);
        LoadData<ReviewData> loadData = new LoadData<>(LoadData.Api.货主认证进度, this);
        loadData._setOnLoadingListener(new LoadingHelper<ReviewData>(layoutContent, loadData) {
            @Override
            public void __onComplete(HttpRequest<Object> request, IHttpResult<ReviewData> data) {
                initView(data.getData());
            }
        });
        loadData._loadData();
    }

    private void initView(ReviewData data) {
        switch (String.valueOf(data.user_status)) {
            case "1"://待审核
                ivImage.setImageResource(R.drawable.iv_shenhe);
                tvMessage.setTextColor(getResources().getColor(R.color.font_blue));
                tvMessage.setText("认证信息审核中.请耐心等待");
                break;
            case "2"://已通过
                ivImage.setImageResource(R.drawable.iv_tongguo);
                tvMessage.setTextColor(Color.parseColor("#59b469"));
                tvMessage.setText("");
                break;
            case "3"://认证失败
                ivImage.setImageResource(R.drawable.iv_shibai);
                tvMessage.setTextColor(getResources().getColor(R.color.red));
                tvMessage.setText(data.reason);
                tvSubmit.setVisibility(View.VISIBLE);
                break;
        }
    }

    @OnClick(R.id.tv_submit)
    public void onViewClicked(View v) {
        switch (v.getId()) {
            case R.id.tv_submit:
                startActivityForResult(new Intent(v.getContext(), ModifyGoodsBossActivity.class), REQUEST_ID);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_ID && RESULT_OK == resultCode) {
            setResult(RESULT_OK);
            finish();
        }
    }
}
